const SUCCESS_CODE = 200;
const FAIL_CODE = 400;
// 随机响应时间
const RESPONSE_TIME_FN = function() {
    let list = [50, 150, 180, 240, 300, 500, 800, 1200, 2000];
    let index = Math.round(Math.random() * (list.length - 1));
    return list[index];
}
// 随机成功概率
const RANDOM_SUCCESS_FN = function() {
    let total = 100; // 总概率
    let fail_rate = 1; // 失败概率
    let result = Math.round(Math.random() * (total - 1)); // 随机数
    return result >= fail_rate; // 如果随机数大于 失败概率 即为成功
}

// 手机号授权登录 POST
function mock_getPhoneNumber(code) {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "SUCCESS",
            "code": SUCCESS_CODE,
            "data": "JE67TyKoD6TvUom7iBynzFz7bTNWasFm3hVhGL2Vrsg1p9lhusJx81BuQ6F3S9Y6xEwWimNVGc7EmessROPA5gMkXJtUmRETUAlLDwmrxyQtQYNAZ50Mk0dSFPOIU46Y",
            "extra": {}

        }
        let fail = {
            "message": "登录失败",
            "code": FAIL_CODE,
            "data": "登录失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 获取用户信息 POST
function mock_system_user_getCurrentUserInfo() {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "获取当前登录用户信息成功",
            "code": SUCCESS_CODE,
            "data": {
                "id": "1",
                "username": "shiyi",
                "nickname": "拾壹", //昵称
                "avatar": "http://img.shiyit.com/chihuo.png", //头像
                "intro": "努力努力再努力", // 个性签名
                "status": 1,
                "sex": "0", //性别
                "roleId": 1
            },
            "extra": {}
        }
        let fail = {
            message: "获取用户信息失败",
            code: FAIL_CODE,
            data: null,
            extra: {}
        }
        setTimeout(() => {
            console.log("mock sendSMS response", result);
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 退出登录 GET
function mock_logout() {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "SUCCESS",
            "code": SUCCESS_CODE,
            "data": " 退出成功",
            "extra": {}
        }
        let fail = {
            "message": "退出登录失败",
            "code": FAIL_CODE,
            "data": "退出登录失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 获取书籍列表 GET
function mock_v1_category(pageNo, pageSize) {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "成功",
            "code": 200,
            "data": {
                "records": [{
                        "id": 17,
                        "name": "后端开发", //书名
                        "picture": "tupian", // 图片地址 http形式
                        "clickVolume": 0,
                        "sort": 10,
                        "memberFlag": 0, // 本书是否会员  0 否 1是
                        "icon": "el-icon-monitor",
                        "articleCount": 0,
                        "createTime": "2021-12-29 14:00:49",
                        "updateTime": null
                    },
                    {
                        "id": 31,
                        "name": "前端开发",
                        "picture": "tupian",
                        "clickVolume": 0,
                        "sort": 9,
                        "memberFlag": 0,
                        "icon": "el-icon-mouse",
                        "articleCount": 0,
                        "createTime": "2023-06-21 15:04:31",
                        "updateTime": null
                    }
                ],
                "total": 8,
                "size": 2,
                "current": 1,
                "orders": [],
                "optimizeCountSql": true,
                "hitCount": false,
                "searchCount": true,
                "pages": 4
            },
            "extra": {}
        }

        let fail = {
            "message": "获取书籍列表失败",
            "code": FAIL_CODE,
            "data": "获取书籍列表失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 获取书籍章节 GET
function mock_v1_article(pageNo, pageSize, categoryId) {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "成功",
            "code": 200,
            "data": {
                "records": [{
                    "id": 14,
                    "userId": "1",
                    "username": "",
                    "userAvatar": "",
                    "title": "关于博客",
                    "avatar": "https://tva2.sinaimg.cn/large/9bd9b167ly1g2rmpwaxkkj21hc0u0e81.jpg", //图片地址
                    "summary": "关于博客的一些介绍。",
                    "content": null,
                    "isStick": 0,
                    "isOriginal": 1,
                    "isPublish": null,
                    "quantity": 1,
                    "commentCount": null,
                    "likeCount": null,
                    "collectCount": 0,
                    "isCollect": null,
                    "commentContent": null,
                    "categoryName": "博客文档",
                    "categoryId": "32",
                    "createTime": "2021-10-15 09:57:22",
                    "formatCreateTime": null,
                    "tagList": null,
                    "englishTitle": "1",
                    "englishContent": "1"
                }],
                "total": 1,
                "size": 2,
                "current": 1,
                "orders": [],
                "optimizeCountSql": true,
                "hitCount": false,
                "searchCount": true,
                "pages": 1
            },
            "extra": {}
        }

        let fail = {
            "message": "获取章节列表失败",
            "code": FAIL_CODE,
            "data": "获取章节列表失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 获取文章内容 GET
function mock_v1_article_info(id) {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "成功",
            "code": 200,
            "data": {
                "id": 14,
                "userId": "1",
                "username": null,
                "title": "关于博客", // 中文标题
                "englishTitle": "1", // 英语标题
                "avatar": null, // 图片地址 http
                "summary": null,
                "originalExplanationAudio": null, // 讲解mp3地址
                "originalExplanationPdf": null, // 讲解pdf 地址
                "content": "<blockquote>\n<p>本文主要介绍博客用到的技术和一些功能详情</p>\n</blockquote>\n<h4><a id=\"1_1\"></a>1、博客使用到的技术</h4>\n<ol>\n<li>后端：springboot，mysql，es搜索引擎，以及redis</li>\n<li>前端：vue</li>\n</ol>\n<h4><a id=\"2_5\"></a>2、首页登录</h4>\n<p>本博客支持<a href=\"https://connect.qq.com/index.html\" target=\"_blank\">QQ</a>、<a href=\"https://gitee.com/api/v5/oauth_doc#/\" target=\"_blank\">gitee</a>、<a href=\"https://open.weibo.com/?bottomnav=1&amp;wvr=6\" target=\"_blank\">微博</a>、微信公众号登录</p>\n<h4><a id=\"3_7\"></a>3、图片的存储</h4>\n<p>项目中图片存储采用的是<a href=\"https://www.qiniu.com/products/kodo\" target=\"_blank\">七牛云</a>平台的对象存储，因为只有七牛云每个月会有免费的一个额度，其他的都是需要收费的。</p>\n<h4><a id=\"4_9\"></a>4、首页的搜索</h4>\n<p>首页的搜索采用的是es的搜索，eslinux启动的话会占用比较高的一个内存，所以博主介意如需要使用es搜索的购买服务器时资金允许的情况下尽可能购买内存比较多的服务器。然后项目搜索的话主要是围绕文章的标题和内容进行的分词搜索。</p>\n<h3><a id=\"_13\"></a>后台管理</h3>\n<blockquote>\n<p><a href=\"http://www.shiyit.com/admin\" target=\"_blank\">后台地址</a><br />\n演示账号：test,密码：test</p>\n</blockquote>\n<h4><a id=\"1_16\"></a>1、登录界面</h4>\n<p><img src=\"http://img.shiyit.com/1639989154384.jpg\" alt=\"login.jpg\" /></p>\n<h4><a id=\"2_18\"></a>2、后台首页</h4>\n<p><img src=\"http://img.shiyit.com/1639989162006.png\" alt=\"adminhome1.png\" /><br />\n<img src=\"http://img.shiyit.com/1639989170907.png\" alt=\"adminhome2.png\" /></p>\n<h4><a id=\"3_21\"></a>3、文章管理</h4>\n<ol>\n<li>列表页<br />\n<img src=\"http://img.shiyit.com/1639989186471.png\" alt=\"文章列表.png\" /></li>\n<li>文章添加<br />\n<img src=\"http://img.shiyit.com/1639989202706.png\" alt=\"文章添加.png\" /><br />\n编辑器使用的是mavon-editor编辑器，如不会使用的可以点击下面的链接查看<br />\n<a href=\"https://blog.csdn.net/qq_43681948/article/details/101531303\" target=\"_blank\">Vue markdown编辑器</a></li>\n</ol>\n<h4><a id=\"4_28\"></a>4、标签管理</h4>\n<p><img src=\"http://img.shiyit.com/1639989247680.png\" alt=\"标签列表.png\" /></p>\n<h4><a id=\"5_30\"></a>5、日志管理</h4>\n<ol>\n<li>针对用户访问以及管理员操作和异常信息都做了一个日志的记录</li>\n</ol>\n<p><img src=\"http://img.shiyit.com/1639989291127.png\" alt=\"日志管理.png\" /></p>\n<h4><a id=\"6_34\"></a>6、系统管理</h4>\n<p><img src=\"http://img.shiyit.com/1639989383160.png\" alt=\"系统配置.png\" /></p>\n<h4><a id=\"7_36\"></a>7、监控中心</h4>\n<ol>\n<li>监控中心主要有服务器的监控和定时任务，定时任务支持自动添加修改删除功能，改了时间无需修改代码<br />\n<img src=\"http://img.shiyit.com/1639989456867.png\" alt=\"定时任务.png\" /></li>\n</ol>\n<h4><a id=\"_39\"></a>结尾</h4>\n<p>上述只是项目的一些基础的功能图片，小伙伴们可以自行登录去查看，后台管理所看到的菜单功能都已实现，还在着手后续的一些功能开发。后台管理全由我自己根据模板改造而来，毕竟我只会业余的前端技术，所以有所缺陷也属正常。如有比较有意思的功能欢迎各位小伙伴给我留言，作者觉得有意思的话就会着手开发。如本项目小伙伴觉得可以，希望能够码云star一下，万分感谢！！</p>\n<blockquote>\n<p>码云地址：<a href=\"https://gitee.com/quequnlong/shiyi-blog\" target=\"_blank\">点我进入</a></p>\n</blockquote>\n<h1><a id=\"bye_42\"></a>bye</h1>\n", // 中文
                "englishContent": "1", // 英语内容

                "isStick": null,
                "isPublish": 1,
                "isOriginal": 1,
                "originalUrl": null,
                "keywords": null,
                "readType": 0,
                "quantity": 1,
                "likeCount": null,
                "commentCount": 0,
                "createTime": 1634227200000,
                "updateTime": 1703880000000,
                "tagList": [{
                    "id": 10,
                    "name": "博客",
                    "sort": 9,
                    "clickVolume": 679,
                    "createTime": "2021-11-12 14:43:27",
                    "updateTime": "2023-06-05 03:00:00"
                }],
                "category": {
                    "id": 32,
                    "name": "博客文档",
                    "clickVolume": null,
                    "sort": null,
                    "icon": null,
                    "createTime": null,
                    "updateTime": null
                },
                "isLike": false,
                "isCollect": 0,
                "isFollowed": 0,
                "collectCount": 0,
                "activeReadType": false,
                "apiCommentListVos": null,
                "userInfo": null
            },
            "extra": {}
        }


        let fail = {
            "message": "获取文章内容失败",
            "code": FAIL_CODE,
            "data": "获取文章内容失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 获取重点词汇
/**
   subjectContent           "englishWord": "2", // 单词
                            "chineseTranslation": "2", // 中文释义
                            "englishTranslation": "2", // 英文短语释义
                            "picture": "2", // 图片地址 http
                            "audioFrequency": "2", // 读音(目前不用 用下面的调用单词发音接口)
 */
function mock_system_articleExercises_list(articleId, questionTypeId) {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "成功",
            "code": 200,
            "data": {
                "1": [{
                        "id": 180,
                        "categoryId": 1,
                        "articleId": 1,
                        "questionTypeId": 1,
                        "questionTypeName": "重点词汇",
                        "questionNumber": 1,
                        "stem": null,
                        "subjectContent": "{\"englishWord\":\"A\",\"chineseTranslation\":\"aaaaaaaaa\",\"englishTranslation\":\"aaaaaaaaa\",\"picture\":\"aaaaaaaaa\",\"audioFrequency\":\"aaaaaaaaa\"}\r\n",
                        "deleteFlag": 0,
                        "createTime": "2024-01-22 23:06:08",
                        "updateTime": null,
                        "createUserId": null,
                        "createUserName": null,
                        "updateUserId": null,
                        "updateUserName": null
                    },
                    {
                        "id": 181,
                        "categoryId": 1,
                        "articleId": 1,
                        "questionTypeId": 1,
                        "questionTypeName": "重点词汇",
                        "questionNumber": 2,
                        "stem": null,
                        "subjectContent": "{\"englishWord\":\"A\",\"chineseTranslation\":\"aaaaaaaaa\",\"englishTranslation\":\"aaaaaaaaa\",\"picture\":\"aaaaaaaaa\",\"audioFrequency\":\"aaaaaaaaa\"}\r\n",
                        "deleteFlag": 0,
                        "createTime": "2024-01-22 23:06:08",
                        "updateTime": null,
                        "createUserId": null,
                        "createUserName": null,
                        "updateUserId": null,
                        "updateUserName": null
                    }
                ]
            },
            "extra": {}
        }

        let fail = {
            "message": "获取重点词汇失败",
            "code": FAIL_CODE,
            "data": "获取重点词汇失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}

// 文件上传 POST
function mock_file_upload() {
    return new Promise((resolve, reject) => {
        let success = {
            "message": "SUCCESS",
            "code": 200,
            "data": "http://101.201.61.220/readSystem/img/3b7de1024d8f4c59968da353d7825f79.jpg", //地址 修改的时候传
            "extra": {}
        }


        let fail = {
            "message": "获取重点词汇失败",
            "code": FAIL_CODE,
            "data": "获取重点词汇失败",
            extra: {}
        }
        setTimeout(() => {
            resolve(RANDOM_SUCCESS_FN() ? success : fail)
        }, RESPONSE_TIME_FN())
    })
}